package com.rt.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rt.common.annotation.Log;
import com.rt.common.core.controller.BaseController;
import com.rt.common.core.domain.AjaxResult;
import com.rt.common.enums.BusinessType;
import com.rt.system.domain.WebArea;
import com.rt.system.service.IWebAreaService;
import com.rt.common.utils.poi.ExcelUtil;
import com.rt.common.core.page.TableDataInfo;

/**
 * 地市Controller
 * 
 * @author Yg
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/area")
public class WebAreaController extends BaseController
{
    @Autowired
    private IWebAreaService webAreaService;

    /**
     * 查询地市列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WebArea webArea)
    {
        startPage();
        List<WebArea> list = webAreaService.selectWebAreaList(webArea);
        return getDataTable(list);
    }

    /**
     * 导出地市列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "地市", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WebArea webArea)
    {
        List<WebArea> list = webAreaService.selectWebAreaList(webArea);
        ExcelUtil<WebArea> util = new ExcelUtil<WebArea>(WebArea.class);
        return util.exportExcel(list, "地市数据");
    }

    /**
     * 获取地市详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(webAreaService.selectWebAreaById(id));
    }

    /**
     * 新增地市
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "地市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebArea webArea)
    {
        return toAjax(webAreaService.insertWebArea(webArea));
    }

    /**
     * 修改地市
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "地市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebArea webArea)
    {
        return toAjax(webAreaService.updateWebArea(webArea));
    }

    /**
     * 删除地市
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "地市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(webAreaService.deleteWebAreaByIds(ids));
    }
}
